#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import random

class Person(object):
    def __init__(self, name, age, gender='男'):
        self.name = name
        self.age = age
        self.gender = gender

    def __add__(self, other):
        # 合法婚姻关系 +
        # Person , Person -> Person
        if self & other:
            if self.gender == '男':
                name = self.name[0] + random.choice((other.name[1:], self.name[1:]))
            else:
                name = other.name[0] + random.choice((other.name[1:], self.name[1:]))
            gender = random.choice(('男', '女'))
            return Person(name, 0, gender)

    def __str__(self):
        # 字符串表示
        return '%s (%d, %s)' % (self.name, self.age, self.gender)


    def __and__(self, other):
        # 合法婚姻关系 &
        if self.gender == '男' and other.gender == '女':
            if self.age >= 22 and other.age >= 20:
                return True
            else:
                print('无效婚姻关系')
        elif self.gender == '女' and other.gender == '男':
            if self.age >= 20 and other.age >= 22:
                return True
            else:
                print('无效婚姻关系')
        else:
            print('无效婚姻关系')
       
a = Person('赵丽颖', 31, gender='女')
b = Person('冯绍峰', 40, gender='男')
c = Person('王源', 18, gender='男')

print(a + b)
